echo "创建上传脚本"
cat << ==EOF== > upload_server.py

import os
import fire
import pywebio
from pywebio.input import file_upload
from pywebio.output import put_text


def upload_file():
    """
    使用pywebio实现文件上传服务
    :return:
    """
    # 注意指定binary避免编码错误
    file_info = file_upload("上传文件", placeholder="请选择文件", binary=True)
    if file_info:
        open('asset/' + file_info['filename'], 'wb').write(file_info['content'])
        put_text("上传文件成功")
    else:
        put_text("请选择文件！")


def main(server_port=8801):
    """
    简单的文件上传服务
    :param server_port: 服务端口
    :return:
    """
    pywebio.start_server(upload_file, port=server_port)


if __name__ == '__main__':
    fire.Fire(main())


==EOF==

echo "请调整和使用后面命令来安装依赖: pip install pywebio fire"
echo "请调整和使用后面命令来启动服务: python upload_server.py --server_port=8011"
